<template>
  <el-form :model="formInline" class="form-inline">
    <el-row class="row"
      ><el-form-item label="预案名称：">
        <el-input
          v-model="formInline.name"
          placeholder="--请输入--"
        ></el-input> </el-form-item
      ><el-form-item label="预案类型：">
        <el-select
          v-model="formInline.type"
          @change="change"
          placeholder="--请选择--"
          @click="select"
        >
          <el-option
            v-for="item in options.value"
            :key="item.type"
            :label="item.type"
            :value="item.type"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="上传时间：">
        <el-date-picker
          v-model="date"
          type="datetimerange"
          :shortcuts="shortcuts"
          format="YYYY-MM-DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
          range-separator="~"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          @change="dateChange"
          size="small"
        />
      </el-form-item>
      <el-form-item class="btns">
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="success" @click="onClear">清空</el-button>
      </el-form-item>
    </el-row>
  </el-form>
</template>

<script setup>
import { reactive, defineEmits, ref } from 'vue'
import { ListType } from '@/api/reserveData'

const startDate = ref(null)
const date = ref([])
const shortcuts = [
  {
    text: '上个星期',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
      return [start, end]
    }
  },
  {
    text: '上个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      return [start, end]
    }
  },
  {
    text: '前三个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
      return [start, end]
    }
  }
]
const formInline = reactive({
  name: '',
  type: '',
  time: ''
})

const emits = defineEmits(['onSearch'])
const options = reactive({})
const select = () => {
  type()
}
const type = async () => {
  const res = await ListType()
  options.value = res
}

type()

const change = (options) => {
  // console.log('options', options)
  // console.log('formInline', formInline)
}
const dateChange = (date) => {
  console.log('dateChange', date)
  formInline.time = date
}

const onSubmit = () => {
  emits('onSearch', formInline)
}
const onClear = () => {
  console.log('formInline', formInline)
  formInline.type = ''
  formInline.name = ''
  formInline.time = ''
  date.value = []
  emits('onSearch', formInline)
}
</script>

<style lang="scss" scoped>
.form-inline {
  width: 100%;
  position: relative;
  // display: flex;
  // column-gap: 20px;
  // padding-bottom: 33px;
  .row {
    display: flex;
    flex-wrap: wrap;
    column-gap: 5%;
  }
  .btns {
    position: absolute;
    right: 0;
    top: 1px;
    .m-left {
      margin-left: 20px;
    }
  }
}
:deep(.el-range-editor--small .el-range-separator) {
  line-height: 30px;
}
</style>
